1. Field of the Invention
This application claims the benefit of Japanese Patent Application No. 2006-161031 filed on Jun. 9, 2006, which is hereby incorporated by reference in its entirety.
The present invention relates to an algebra operation method and apparatus thereof, which can be used in an object-oriented programming language having an operator overloading function.
2. Description of the Related Art
Conventionally, in order to efficiently develop linear algebra operation programs, linear algebra programs and libraries which overload a Matrix class, Vector class, and binary operators having them as operands using an object-oriented programming language such as C++ or the like are used.
According to the object-oriented programming language, a program written in C, as shown in FIG. 1, can be described, as shown in FIG. 2, when operator overloading by C++ is used. For example, please refer to Bjarne Stroustrup: The C++ Programming Language, Addison-Wesley, 2000.
By overloading operators, operations between Matrices and conversions of Vectors by means of Matrices can be simply described without describing any loop processing about suffices.
The object-oriented programming has a merit that allows the user to intuitively recognize correspondence with mathematical expressions in the linear algebra, and to reduce cost required for creating and testing programs.
On the other hand, programming using a non-object-oriented programming language such as C or Fortran normally uses the linear algebra library BLAS for large-scale, high-speed linear algebra programming. For example, please refer to the world-wide-web URL:netlib.org/blas/.
However, since Matrix and Vector operations using overloading of C++ are normally of a scheme that completes a calculation for each binary operation, an overhead readily becomes large. For example, upon calculating C=m*A*B+n*C, processes from step 1 to step 6 are made, as shown in FIG. 3.
For this reason, operations using overloading of C++ have poor memory use efficiency since a memory area for an array is assured every binary operation. Also, in consideration of even an object which is automatically generated by a compiler and is used to store an object returned from an operator, the number of objects which are generated temporarily becomes still larger.
Also, the number of loop processes in the aforementioned programming is apparently larger than the minimum required number of loop processes (FIG. 4). Since data once loaded from a memory may be loaded a number of times, this may cause an increase in calculation time.
Bjarne Stroustrup: The C++ Programming Language, Addison-Wesley, 2000 describes such problem. As a solution to that problem, this reference proposes that for an operation W=M*V+X (W, V, X: Vector, M: Matrix), an object of a new class having a reference to two objects as a member variable (attribute) is generated to be set as a return value of an operation M*V.
However, this method cannot cope with, for example, general operations such as C=m*A*B+n*C and C=m*A*B+n*C. Note that A is the Hermitian conjugate of Matrix A. A problem that a memory area of temporary objects increases when a mathematical expression becomes long like C=m*A*B+n*C*(m*A*B+n*C) remains unsolved. In this manner, the prior art cannot always sufficiently cope with all types of operations in the linear algebra.
On the other hand, the above BLAS normally comes on the market after it is tuned to be suited to the computer architectures. However, the BLAS is not provided to have an interface suited to the object-oriented programming language such as C++ or the like.
The BLAS can implement an operation like equation (1) below by calling only one function. However, it is difficult for the method based on object-oriented programming that completes a calculation every binary operation to calculate that equation by only one function call like in the BLAS.C=αAB+βC  (1)where A, B, and C are Matrices, and α and β are complex numbers.
For this reason, a high-speed linear algebra operation program equivalent to the BLAS cannot be described using operator overloading by the object-oriented programming language such as C++ or the like.